package com.vgulu.server.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Created by Administrator on 2014/7/16 0016.
 */
public class PropertyConfigurer extends PropertyPlaceholderConfigurer {
    private static Map<String, Object> propertiesMap;

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
        super.processProperties(beanFactoryToProcess, props);
        propertiesMap = new HashMap<String, Object>();
        for (Object key : props.keySet()) {
            String keyStr = key.toString();
            String value = props.getProperty(keyStr);
            propertiesMap.put(keyStr, value);

            logger.info(keyStr + " = " + value);
        }
    }
    public static Object getProperty(String name) {
        return propertiesMap.get(name);
    }

    public static String getPropertyAsString(String name){
        return (String) propertiesMap.get(name);
    }

    public static int getPropertyAsInt(String name){
        return Integer.valueOf((String) propertiesMap.get(name));
    }
}
